package mess;

public class LeeCode_20_Failed {
    public static void main(String[] args) {
        System.out.println(isValid("{[]}"));
    }
    public static boolean isValid(String s) {
        int len = s.length();
        if (len % 2 != 0)
            return false;
        int i = 0;
        while (i < len) {
            switch (s.charAt(i)){
                case '(':
                    if (s.charAt(i + 1) != ')')
                        return false;
                    i += 2;
                    break;
                case '[':
                    if (s.charAt(i + 1) != ']')
                        return false;
                    i += 2;
                    break;
                case '{':
                    if (s.charAt(i + 1) != '}')
                        return false;
                    i += 2;
                    break;
                default:
                    return false;
            }
        }
        return true;
    }
}
